package udpecho

import (
	"context"
	"fmt"
	"nprobe/core"
)

func NewUDPEchoReceiverGroup(
	ctx context.Context, name string, task *core.ProbeTask, maxPPSPerReceiver int, salts map[int][]byte,
) *core.ReceiverGroup {
	var receivers []core.Receiver

	targetCnt := len(task.DstIPs)
	totalPPS := task.PPS * targetCnt
	receiverCnt := (totalPPS + maxPPSPerReceiver - 1) / maxPPSPerReceiver

	targetSet := make(map[string]bool)
	for _, target := range task.DstIPs {
		targetSet[target] = true
	}

	for i := 0; i < receiverCnt; i++ {
		receiver := NewUDPEchoReceiver(ctx, fmt.Sprintf("%s-receiver-%d", name, i), i, task, salts, targetSet)
		receivers = append(receivers, receiver)
	}

	return &core.ReceiverGroup{Ctx: ctx, Name: name + "-receiver-group", Receivers: receivers}
}
